//
//  MainViewController.swift
//  Sinaweibo
//
//  Created by 李伟 on 16/2/16.
//  Copyright © 2016年 一苇渡江. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc func plusBtnDidClick() {
    
    }
    
    // 相当于控制器入口 OC的viewDidLoad方法
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar = MainTabbar()
        
        setValue(mainTabbar, forKey: "tabBar")
        
        let actionName = "plusBtnDidClick"
        
        mainTabbar.plusBtn.addTarget(self, action: Selector(actionName), forControlEvents: .TouchUpInside)
        
        
        addChildViewControllers()

    }

    // 添加子视图控制器
    private func addChildViewControllers() {
        
        addChildViewcontroller(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewcontroller(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewcontroller(DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewcontroller(ProfileViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    // 添加单个视图控制器
    private func addChildViewcontroller(vc: UIViewController,title: String,imageName: String) {
        
        // 设置tabbar渲染的颜色
        tabBar.tintColor = UIColor.orangeColor()
        
        let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        
//        vc.tabBarItem.title = "lll" 设置底部tabbar的标题
        
//        vc.navigationItem.title = "fdf" 设置顶部导航条的标题
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
        
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
